<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>

<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<title>MOXI</title>

<link th:href="@{/css/bootstrap.min.css}" rel="stylesheet" />
<link th:href="@{/font-awesome/css/font-awesome.css}" rel="stylesheet" />

<!-- Toastr style -->
<link th:href="@{/css/plugins/toastr/toastr.min.css}" rel="stylesheet"/>

<link th:href="@{/css/style.css}" rel="stylesheet" />

<!-- summernote style -->
<link th:href="@{/css/plugins/summernote/summernote.css}" rel="stylesheet" />
<link th:href="@{/css/plugins/summernote/summernote-bs3.css}" rel="stylesheet" />

</head>

<body>

    <div id="wrapper">
		<nav class="navbar-default navbar-static-side" role="navigation" th:include="nav :: navigation"></nav>
		<div id="page-wrapper" class="gray-bg">
        	<div class="border-bottom" th:include="header :: headerTop"></div>
      		<div class="row wrapper border-bottom white-bg page-heading" th:fragment="headerNav">
		   		<div class="col-lg-10">
		     		<h2>文章管理</h2>
		          	<ol class="breadcrumb">
			            <li>
			            	<a href="#">首页</a>
			            </li>
			            <li>
			            	<a>内容管理</a>
			         	</li>
			         	<li>
			             	<a>文章管理</a>
			          	</li>
			          	<li class="active">
			             	<strong>文章新增</strong>
			          	</li>
					</ol>
		      	</div>
		      	<div class="col-lg-2">
		      	</div>
		  	</div>
        	<div class="wrapper wrapper-content animated fadeInRight">
            
            
            
            <div class="row">
                <div class="col-lg-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-title">
                            <h5>新增文章</h5>
                            <div class="ibox-tools">
                                <a class="collapse-link">
                                    <i class="fa fa-chevron-up"></i>
                                </a>
                            </div>
                        </div>
                        <div class="ibox-content">
                            <form id="formTag" action="newsEdit" method="POST" class="form-horizontal" enctype="multipart/form-data">
                            	
                            	<input type="hidden" name="id" th:value="${news.id}" />
                            	<input type="hidden" name="image" th:value="${news.image}" />
                            	<input type="hidden" name="content" id="content" th:value="${news.content}" />
                            	
                                <div class="form-group"><label class="col-sm-2 control-label">标题：</label>
                                    <div class="col-sm-10">
                                    	<input id="title" name="title" type="text" class="form-control" th:value="${news.title}"/>
                                    </div>
                                </div>
                                
                                <div class="hr-line-dashed"></div>
                                
                                <div class="form-group"><label class="col-sm-2 control-label">分类：</label>
                                    <div class="col-sm-10">
	                                    <select name="category" id="category" class="form-control" >
	                                    	<option value="0" th:selected="${news.category==0}">--请选择文章分类--</option>
                                            <option th:each="nc : ${newsCategoryList}" th:value="${nc.id}" th:text="${nc.name}" th:selected="${nc.id==news.category}">分类</option>
                                        </select>
                                    </div>
                                </div>
                                
                                <div class="hr-line-dashed"></div>
                                
                                <div class="form-group"><label class="col-sm-2 control-label">描述：</label>
                                    <div class="col-sm-10">
                                    	<textarea id="description" name="description" class="form-control" rows="2" th:text="${news.description}"></textarea>
                                    </div>
                                </div>
                                
                                <div class="hr-line-dashed"></div>
                                
                                <div id="imageCell" class="form-group"><label class="col-sm-2 control-label">图片：</label>
                                    <div class="col-sm-10">
                                    	<img  th:src="@{${news.image}}" />
                                    	<button id="imageCellBut" type="button" class="btn btn-white btn-sm">&nbsp;&nbsp;&nbsp;&nbsp;修改&nbsp;&nbsp;&nbsp;&nbsp;</button>
                                    </div>
                                </div>
                                
                                <div id="imputCell" class="form-group"><label class="col-sm-2 control-label">图片：</label>
                                    <div class="col-sm-10">
                                    	<input id="imageFile" name="imageFile" type="file" />
                                    </div>
                                </div>
                                
                                <div class="hr-line-dashed"></div>
                                
                                <div id="imputCell" class="form-group"><label class="col-sm-2 control-label">内容：</label>
                                    <div class="col-sm-10">
										<div id="summernote"></div>
                                    </div>
                                </div>
                                
                                <div class="hr-line-dashed"></div>
                                <div class="form-group">
                                    <div class="col-sm-4 col-sm-offset-2">
                                        <button id="submitButton" class="btn btn-primary" type="button">&nbsp;&nbsp;&nbsp;&nbsp;提&nbsp;&nbsp;&nbsp;&nbsp;交&nbsp;&nbsp;&nbsp;&nbsp;</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
            
            </div>
        	<div class="footer" th:include="footer :: copyright"></div>
      	</div>
	</div>
	
    <!-- Mainly scripts -->
    <script th:src="@{/js/jquery-2.1.1.js}"></script>
    <script th:src="@{/js/bootstrap.min.js}"></script>
    <script th:src="@{/js/plugins/metisMenu/jquery.metisMenu.js}"></script>
    <script th:src="@{/js/plugins/slimscroll/jquery.slimscroll.min.js}"></script>
	
    <!-- Peity -->
    <script th:src="@{/js/plugins/peity/jquery.peity.min.js}"></script>
    
    <!-- Custom and plugin javascript -->
    <script th:src="@{/js/inspinia.js}"></script>
    <script th:src="@{/js/plugins/pace/pace.min.js}"></script>
    
    <!-- Toastr script -->
    <script th:src="@{/js/plugins/toastr/toastr.min.js}"></script>
    
    <!-- common -->
    <script th:src="@{/js/common.js}"></script>
    
    <!-- SUMMERNOTE -->
    <script th:src="@{/js/plugins/summernote/summernote.min.js}"></script>
    
    <script th:inline="javascript">
        var image = [[${news.image}]];
		$(document).ready(function () {
			if(image==null || image==""){
				$("#imageCell").hide();
				$("#imputCell").show();
			} else {
				$("#imageCell").show();
				$("#imputCell").hide();
			}
			$("#imageCellBut").click(function(){
				$("#imageCell").hide();
				$("#imputCell").show();
			});
		});
    </script>
    
    <script th:inline="javascript">
    	var content = [[${news.content}]];
		$(document).ready(function () {
			//初始化编辑器
			$('#summernote').summernote({
			    height: 300,
			    codemirror: {
			      mode: 'text/html',
			      htmlMode: true,
			      lineNumbers: true,
			      theme: 'monokai'
			    }
			});
			//编辑器赋值
			$('#summernote').code(content);
			
			//提交
			$("#submitButton").click(function(){
				if($("#title").val() == ""){
					toastr.error('请输入文章标题','提示');
					return;
				}
				if($("#category").val() == 0){
					toastr.error('请选择文章分类','提示');
					return;
				}
				var markupStr =  $('#summernote').code();
				if(markupStr == ""){
					toastr.error('请填写文章内容','提示');
					return;
				}
				$("#content").val(markupStr);
				$("#formTag").submit();
			});
		});
    </script>

</body>

</html>
